let list = document.querySelectorAll('.btn')
for (let item of list) {
  item.onclick = getNum()
}

function getNum() {
  let num = 1
  return function () {
    this.previousElementSibling.innerHTML = ++num
  }
}

function getObject() {
  return {}
}
let o1 = getObject()
let o2 = getObject()
console.log(o1 === o2) // false

// 获得所有的li节点的序号和内容
let li_list = document.querySelectorAll('li')
for (let i = 0; i < li_list.length; i++) {
  li_list[i].onclick = (function (n) {
    return function () {
      alert(n + ',' + this.innerHTML)
    }
  })(i)
}

// 使用闭包返回同一个对象
function createObject() {
  let obj = { id: 1, name: 'tom', age: 20 }
  return () => obj
}
let getObj = createObject()
let obj1 = getObj()
obj1.name = 'sam'
let obj2 = getObj()
obj2.gender = '女'
let obj3 = getObj()
console.log(obj3)
console.log(obj1 === obj2, obj1 === obj3)
